<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // es5组合继承

        // 定义父类
        function User(name, password) {
            this.name = name
            this.password = password
        }

        User.prototype.showName = function () {
            console.log('父类名字', this.name);
        }
        User.prototype.showPass = function () {
            console.log('父类密码', this.password);
        }
        // 子类
        function VipUser(name, password, level) {
            //继承公有属性 通过改变this指向调用（call，apply，bind）
            User.call(this, name, password)
            this.level = level
        }
        //原型链继承
        // VipUser.prototype = new User()
        // VipUser.prototype.showLevel = function () {
        //     console.log('用户级别是', this.level);
        // }
        // let vip = new VipUser('admin', '123456', '三级')
        // vip.showName()
        // vip.showPass()
        // vip.showLevel()

        // 拷贝继承 直接赋值方法 遍历父类所有原型方法赋值给子类原型方法
        VipUser.prototype.showLevel = function () {
            console.log('用户级别是', this.level);
        }
        for (var i in User.prototype) {
            VipUser.prototype[i] = User.prototype[i]
        }
        let vip = new VipUser('admin', '123456', '三级')
        vip.showName()
        vip.showPass()
        vip.showLevel()
    </script>
</body>

</html>